/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.wpi.first.wpilibj.team1662.commands;

import com.sun.squawk.util.MathUtils.*;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.DriverStationLCD;
import edu.wpi.first.wpilibj.buttons.DigitalIOButton;
import edu.wpi.first.wpilibj.networktables.NetworkTable;
import edu.wpi.first.wpilibj.networktables2.client.NetworkTableClient;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.tables.TableKeyNotDefinedException;
import edu.wpi.first.wpilibj.team1662.RobotMap;

/**
 *
 * @author programmer
 */
public class Drive extends CommandBase {
    private DigitalInput limitSwitch = new DigitalInput(RobotMap.limitSwitch);
    private DigitalInput limitSwitch2 = new DigitalInput(RobotMap.limitSwitch2);
    //private boolean test2 = RobotMap.test2;
    private double test;
    
    public Drive() {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
        requires(drivetrain);
    }

    // Called just before this Command runs the first time
    protected void initialize() {
        drivetrain.tankDrive(0, 0);
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute(){
        //if(NetworkTable.getTable("SingleControl").getBoolean("SingleController") == false){
        drivetrain.tankDrive(-oi.getLeftStick(), -oi.getRightStick());
        //SmartDashboard.putNumber("LeftStick value:", oi.getLeftStick());
        //SmartDashboard.putNumber("RightStick value", oi.getRightStick());
        if(limitSwitch.get() != true || limitSwitch2.get() != true)
            drivetrain.cheezit(0);
        else {
            if(oi.getConveyorThrottle() > .1){
                drivetrain.cheezit(-1);
            }
            else if(oi.getConveyorThrottle() < -.1)
                drivetrain.cheezit(-1);
            else
                drivetrain.cheezit(0);

        }
        DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser4, 1, ""+oi.getSomething());
        DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser1, 1, ""+oi.getConveyorThrottle());
        DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser2, 1, ""+drivetrain.getChMotor());
        DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser3, 1, ""+limitSwitch.get());
        //DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser4, 1, ""+test2);
        //System.out.println(SmartDashboard.getBoolean("SingleControl"));
        //System.out.println(SmartDashboard.getBoolean("SingleController"));
        DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser4, 1, ""+oi.getButton());
        DriverStationLCD.getInstance().updateLCD();
    }

    protected double power(double a, double x){
        for(int i = 1; i <= x; i++){
            a*=a;
        }
        return a;
    }
    
    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return false;
    }

    // Called once after isFinished returns true
    protected void end() {
        drivetrain.tankDrive(0, 0);
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
        drivetrain.tankDrive(0, 0);
    }
}